package com.simple.util.exception;

import com.simple.util.common.ErrorUtil;
import com.simple.util.common.Utils;



/**
 * The Class ApebApplicationException.
 */
public class SimpleApplicationException extends Exception implements ISimpleException{    
    /** The Constant serialVersionUID. */
    private static final long serialVersionUID = 0x132dd3c7e6c77714L;
    
    /** The code. */
    private String code;
    
    /** The param. */
    private String[] param;
    
    /** The parent throwable. */
    private Throwable parentThrowable;

    /**
     * Instantiates a new apec application exception.
     * 
     * @param code
     *            the code
     * @param param
     *            the param
     * @param nestedThrowable
     *            the nested throwable
     */
    public SimpleApplicationException(final String code, final String[] param,
            final Throwable nestedThrowable) {
        super();
        this.code = code;
        this.param = Utils.copyArray(param);
        parentThrowable = nestedThrowable;
    }

    /**
     * Instantiates a new apec application exception.
     * 
     * @param code
     *            the code
     * @param param
     *            the param
     */
    public SimpleApplicationException(final String code, final String[] param) {
        this(code, param, null);
    }

    /**
     * Instantiates a new apec application exception.
     * 
     * @param code
     *            the code
     * @param nestedThrowable
     *            the nested throwable
     */
    public SimpleApplicationException(final String code, final Throwable nestedThrowable) {
        this(code, null, nestedThrowable);
    }

    /**
     * Instantiates a new apec application exception.
     * 
     * @param code
     *            the code
     */
    public SimpleApplicationException(final String code) {
        this(code, null, null);
    }

    /**
     * Gets the code.
     * 
     * @return the code
     */
    public final String getCode() {
        return code;
    }

    /**
     * Gets the param.
     * 
     * @return the param
     */
    public final String[] getParam() {
        return Utils.copyArray(param);
    }

    /**
     * Gets the parent throwable.
     * 
     * @return the parent throwable
     */
    public final Throwable getParentThrowable() {
        return parentThrowable;
    }

    /* (non-Javadoc)
     * @see java.lang.Throwable#getMessage()
     */
    public String getMessage() {
        return ErrorUtil.generateStackTraceString(this);
    }
}
